﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ICTBilling;

public partial class WebForms_CenterEquipment : System.Web.UI.Page
{
    private static List<ExceptionHandler> ExecutionCollection = new List<ExceptionHandler>();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void CenterEquipmentFormView_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        if (e.CommandName.ToUpper() == "CANCEL")
            CenterEquipmentFormView.ChangeMode(FormViewMode.Insert);
    }
    protected void CenterEquipmentGridView_SelectedIndexChanged(object sender, EventArgs e)
    {
        CenterEquipmentFormView.PageIndex = (CenterEquipmentGridView.PageSize * CenterEquipmentGridView.PageIndex) + CenterEquipmentGridView.SelectedIndex;
        CenterEquipmentFormView.ChangeMode(FormViewMode.Edit);
        CenterEquipmentGridView.DataBind();
        CenterEquipmentGridView.SelectedIndex = -1;
    }
    protected void ClearImageButton_Click(object sender, ImageClickEventArgs e)
    {
        CenterNameTextBox.Text = CenterPassTextBox.Text = string.Empty;
        ClearImageButton.OnClientClick = "return false;";
    }
    protected void SearchImageButton_Click(object sender, ImageClickEventArgs e)
    {
        CenterEquipmentGridView.PageSize = (PageSizeDropDownList.SelectedIndex == -1 || PageSizeDropDownList.SelectedValue == "0" ? 5 : Convert.ToInt32(PageSizeDropDownList.SelectedValue));
        if (CenterNameTextBox.Text != string.Empty ||
            CenterPassTextBox.Text != string.Empty)
        {
            ClearImageButton.OnClientClick = string.Empty;
        }
        else
            ClearImageButton_Click(sender, e);
    }
    protected void CenterEquipmentEntityDataSource_Command(object sender, EntityDataSourceChangedEventArgs e)
    {
        tbCenterEquipment newsItem = e.Entity as tbCenterEquipment;
        if (e.Entity != null)
            ExecutionCollection.AddRange(newsItem.Validate(CenterEquipmentFormView.CurrentMode == FormViewMode.Edit ? ChangeAction.Update : ChangeAction.Insert));

        CenterEquipmentGridView.DataBind();
        CenterEquipmentFormView.ChangeMode(FormViewMode.Insert);
    }
    protected void CenterGridView_SelectedIndexChanged(object sender, EventArgs e)
    {
        CenterLabel.Text = string.Format("فهرست تجهیزات {0}", CenterGridView.Rows[CenterGridView.SelectedIndex].Cells[2].Text);
        CenterIDHiddenField.Value = CenterGridView.SelectedValue.ToString();
        MultiView.SetActiveView(EditView);
    }
   
    protected void ReturnLinkButton_Click(object sender, EventArgs e)
    {
        MultiView.SetActiveView(ShowView);
    }
    protected void InsertLinkButton_Click(object sender, EventArgs e)
    {
        ((HiddenField)CenterEquipmentFormView.FindControl("CenterIDHiddenField")).Value = CenterIDHiddenField.Value;
    }
}